package com.yanftch.stopcoding.request;

import com.yanftch.stopcoding.cb.RequestCallBack;
import com.yanftch.stopcoding.config.DefaultConfig;

import java.util.HashMap;
import java.util.Map;

/**
 * 请求管理类
 */
public class RequestManager {
    private static Map<Integer, Request> requestMap = new HashMap<>();

    static {
        DefaultConfig.TextSourceEnum[] values = DefaultConfig.TextSourceEnum.values();
        for (DefaultConfig.TextSourceEnum value : values) {
            requestMap.put(value.index, value.request);
        }
    }

    // 根据请求类型执行相应的请求
    public void executeRequest(int type, RequestCallBack callback) {
        Request request = requestMap.get(type);
        if (request != null) {
            request.request(callback);
        } else {
            callback.onError(new Exception("Unknown request type"));
        }
    }
}
